import coords

class Cell:
    def __init__(self, index, mapw):
        self.resourceDensity = 0
        self.obstacle = 0
        self.gridCoords = [0,0]
        self.gridCoords[0] = index%mapw
        self.gridCoords[1] = index//mapw
        self.screenCoords = coords.gridToScreen(self.gridCoords)
        self.hasChanged = False
    
    def addResources(self, resourceDensity):
        self.resourceDensity += resourceDensity
    
    def getResources(self):
        return self.resourceDensity
    
    def getGridCoords(self):
        return self.gridCoords

    def display(self):
        print "Security: "+str(self.resourceDensity) 
        
    def beObstacle(self):     
        self.obstacle = 1
        
    def isObstacle(self):
        return self.obstacle
    
    def mineResources(self):
        minerals = 0
        while minerals <3:
            minerals += 1
            self.resourceDensity -= 1
            if self.resourceDensity == 0:
                #print "minerals:"+str(minerals)
                return minerals
        #print "minerals:"+str(minerals)
        return minerals
        """self.resourceDensity -= 3
        if self.resourceDensity < 0:
            self.resourceDensity = 0"""
"""            
import os, sys, pygame, pygame.font
from pygame.color import THECOLORS
from pygame.locals import *
import imageLoader

class Cell():
    def __init__(self, gridCoords, mapw, screen, screenCoords):
        #pygame.sprite.Sprite.__init__(self)
        self.resourceDensity = 0
        self.obstacle = 0
        print "Accepted grid Coords"+str(gridCoords)
        self.gridCoords = gridCoords
        self.screenCoords = screenCoords
        #self.area = screen.get_rect()
        #self.image, self.rect = imageLoader.load_image('Empty.gif', -1)
        #self.rect.topleft = screenCoords[0], screenCoords[1]
    
    def addResources(self, resourceDensity):
        self.resourceDensity += resourceDensity
    
    def getResources(self):
        return self.resourceDensity
    
    def getGridCoords(self):
        return self.gridCoords

    def display(self):
        print "Resource Density: "+str(self.resourceDensity) 
        
    def beObstacle(self):     
        self.obstacle = 1
        
    def isObstacle(self):
        return self.obstacle
    
    def initialiseSprite(self):
        pass
    
        if self.obstacle == 1:
            self.image = imageLoader.load_image('Debris.gif', -1)
        elif self.resourceDensity > 20:
            self.image = imageLoader.load_image('3Density.gif', -1)
        elif self.resourceDensity > 10:
            self.image = imageLoader.load_image('2Density.gif', -1)
        elif self.resourceDensity > 0:
            self.image = imageLoader.load_image('1Density.gif', -1)
        elif self.resourceDensity == 0:
            self.image = imageLoader.load_image('Empty.gif', -1)
    
    def mineResources(self):
        #resources = 0
        self.resourceDensity -=3
        if self.resourceDensity < 0:
            self.resourceDensity = 0
            
        if self.resourceDensity > 20:
            self.image = imageLoader.load_image('3Density.gif', -1)
        elif self.resourceDensity > 10:
            self.image = imageLoader.load_image('2Density.gif', -1)
        elif self.resourceDensity > 0:
            self.image = imageLoader.load_image('1Density.gif', -1)
        elif self.resourceDensity == 0:
            self.image = imageLoader.load_image('Empty.gif', -1)
        
        
        while resources<=3 & self.resourceDensity>0:
            resources+=1
            self.resourceDensity -=1
        return resources"""